package com.controller;

import com.biz.INoticeBiz;
import com.entity.Discuss;
import com.entity.Notice;
import com.util.PageBean;
import org.apache.ibatis.annotations.Param;
import org.aspectj.weaver.ast.Not;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by Administrator on 2019/1/21/021.
 */

@Controller
@RequestMapping("/notice")
public class NoticeAction {

    @Autowired
    private INoticeBiz biz;

    public INoticeBiz getBiz() {
        return biz;
    }

    public void setBiz(INoticeBiz biz) {
        this.biz = biz;
    }

    //列表所有公告信息
    @RequestMapping("/list")
    public String getAll(HttpSession session)
    {
        List<Notice> list= biz.getAll();
        session.setAttribute("nlist",list);
        return "/back/notice_list";
    }

    //获取最新的五条
    @RequestMapping("/getNewFive")
    @ResponseBody
    public List<Notice> getNewFive(HttpSession session)
    {
        List<Notice> list= biz.getNewFive();
      //  session.setAttribute("newnotice",list);
        return list;
    }


    //增加公告信息
    @RequestMapping("/add")
    public String  add(Notice nn)
    {
        biz.add_notice(nn);
        return "redirect:list.action";/*redirect:list.action*/
    }

    //删除公告信息
    @RequestMapping("/del")
    public String del(int id)
    {
        biz.del_notice(id);
        return "redirect:list.action";/*redirect:list.action*/
    }

    //根据id获取公告信息
    @RequestMapping("/getbyid")
    public ModelAndView getById(int id)
    {
        Notice nn= biz.getById(id);
        ModelAndView mv=new ModelAndView();
        mv.addObject("n", nn);
        mv.setViewName("/back/notice_mod");
        return mv;
    }

    //修改公告信息
    @RequestMapping("/mod")
    public String mod(Notice nn)
    {
        biz.mod_notice(nn);
        return "redirect:list.action";
    }


    //公告列表（分页+不定项）
    @RequestMapping("/list_notice")
    @ResponseBody
    public PageBean getAll_notice(@RequestParam(defaultValue="1")int page, String content, HttpSession session)
    {
        PageBean bean=biz.getPage_notice(page,content);
        session.setAttribute("pb",bean);
        return bean;
    }


}
